#include "Parsers.h"

#include <boost/spirit/include/classic.hpp>

using namespace boost::spirit::classic;


// You gotta love Spirit.
struct transmit_parser : public grammar<transmit_parser>
{
	transmit_parser( UIntVector & ccf, unsigned int & hardwareId, unsigned int & blasters, unsigned int & repeats ) : _ccf(ccf), _blasters(blasters), _repeats(repeats), _hardwareId(hardwareId) {} 
	template<typename ScannerT>
	struct definition
	{
		rule<ScannerT> r;
		definition(transmit_parser const & self )
		{
			r = str_p("t") >> +space_p >> uint_p[assign_a(self._hardwareId)]>> +space_p >> uint_p[assign_a(self._blasters)] >> +space_p >> uint_p[assign_a(self._repeats)] >> +( +space_p >> hex_p[push_back_a(self._ccf)] ) >> *space_p;
		}
		rule<ScannerT> const & start () const { return r; }
	};
	

	UIntVector & _ccf;
	unsigned int & _hardwareId;
	unsigned int & _blasters;	
	unsigned int & _repeats;
};


bool transmitParser(const std::string & s, UIntVector & ccf, unsigned int & hardwareId,  unsigned int & blasters, unsigned int & repeats )
{
	transmit_parser p(ccf, hardwareId, blasters, repeats);
	return parse ( s.begin(), s.end(), p).full;
}

